/**
 * 联动获取商品信息
 * @param goodId
 * @returns {*}
 */
async function getGoodInfoById(goodId) {
    if (goodId == null || goodId <= 0) {
        return {};
    }
    //ajax获取商品信息
    var goodInfo = await new Promise((resolve, reject) => {
        layui.use("jquery", function () {
            var $ = layui.jquery;
            $.ajax({
                url: '/sys/getGoodsInfoByCode',
                type: 'GET',
                async: false,
                data: {'goodsCode': goodId},
                success: function (result) {
                    var goods = result.data;
                    var goodItem = {
                        goodCode: goods.goodsCode,
                        goodName: goods.goodsName,
                        varietyCode: goods.varietyCode,
                        varietyName: goods.varietyName,
                        standardCode: goods.standardCode,
                        standardName: goods.standardName,
                        unitCode: goods.unitCode,
                        unit: goods.unit,
                        taxRate: goods.taxRate
                    };
                    resolve(goodItem);
                },
                error: function (error) {
                    layer.msg('初始化商品数据失败,请联系管理员');
                    reject(error);
                }
            });
        });
    }).then((result) => {
        return result;
    });
    return goodInfo;
}

/**
 * 清楚所有的空obj
 * @param data
 * @returns {*}
 */
function trimAllArray(data) {
    if (!Array.isArray(data)) {
        return data;
    }

    var newdata = [];
    data.forEach(function (currval, index, arr) {
        if (JSON.stringify(currval) === "{}" || JSON.stringify(currval) === "[]") {
            return;
        }
        newdata.push(currval);
    });
    return newdata;
}